package com.bt.lms.ui.page.classes;

import com.bt.lms.ui.action.divide.plan.BackBtnAction;
import com.bt.lms.ui.action.divide.plan.ShiftBtnAction;
import com.bt.lms.ui.vo.StudentListProperty;
import com.bt.lms.ui.vo.ViewResultProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;

import java.util.ArrayList;

/**
 * 查看学员页面
 */
public class ViewStudents extends VBox {
    /**
     * 宽
     */
    private Integer preWidth = 1280;

    /**
     * 高
     */
    private Integer preHeight = 600;

    public ViewStudents() {
        this.setPrefSize(preWidth, preHeight);
        this.setSpacing(20);
        this.setPadding(new Insets(20));

        //头部标签
        Label topLab = new Label("招生计划B学员名单");
        Font font = Font.font("仿宋", FontWeight.BLACK, FontPosture.REGULAR,25);
        topLab.setFont(font);
        //搜索选项
        HBox hBox = new HBox();
        hBox.setSpacing(20);
        Label planLab = new Label("该招生计划尚未分班！");
        Button shiftBtn = new Button("进行分班");
        shiftBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        //分班按钮事件
        ShiftBtnAction shiftBtnAction = new ShiftBtnAction();
        shiftBtn.setOnAction(shiftBtnAction);

        Color rgb = Color.rgb(49,193,231);
        BackgroundFill backgroundFill = new BackgroundFill(rgb,null,null);
        Background background = new Background(backgroundFill);
        shiftBtn.setBackground(background);

        Label codeLab = new Label("学员编号");
        TextField codeTF = new TextField();
        Label nameLab = new Label("姓名");
        TextField nameTF = new TextField();
        Button searchBtn = new Button("搜索");
        searchBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        hBox.getChildren().addAll(planLab,shiftBtn,codeLab,codeTF,nameLab,nameTF,searchBtn);
        //表
        TableView table = new TableView();
        //创建列
        TableColumn iDXClu = new TableColumn("序号");
        iDXClu.setPrefWidth(80);
        TableColumn stuNOClu = new TableColumn("学员编号");
        stuNOClu.setPrefWidth(80);
        TableColumn nameClu = new TableColumn("姓名");
        nameClu.setPrefWidth(80);
        TableColumn genderClu = new TableColumn("性别");
        genderClu.setPrefWidth(120);
        TableColumn majorClu = new TableColumn("专业");
        majorClu.setPrefWidth(120);
        TableColumn classRoomClu = new TableColumn("班级");
        classRoomClu.setPrefWidth(120);
        TableColumn studyCenterClu = new TableColumn("学习中心");
        studyCenterClu.setPrefWidth(120);
        TableColumn trainingClu = new TableColumn("培训项目");
        trainingClu.setPrefWidth(120);
        TableColumn epnPlanClu = new TableColumn("招生计划");
        epnPlanClu.setPrefWidth(120);
        TableColumn mobileNOClu = new TableColumn("手机号码");
        mobileNOClu.setPrefWidth(120);
        //表里放入列
        table.getColumns().addAll(iDXClu,stuNOClu,nameClu,genderClu,majorClu,classRoomClu,studyCenterClu,trainingClu,epnPlanClu,mobileNOClu);
        StudentListProperty studentListProperty01 = new StudentListProperty(1,2030,"陆小七","男","专业A","未分班","北京","培训项目A","招生计划A","13581801095");
        StudentListProperty studentListProperty02 = new StudentListProperty(2,2031,"陆小八","男","专业A","未分班","上海","英语培训","招生计划A","13581807095");
        StudentListProperty studentListProperty03 = new StudentListProperty(3,2032,"陆小九","男","专业A","未分班","江苏","计算机基础","招生计划A","13581601095");
        StudentListProperty studentListProperty04 = new StudentListProperty(4,2033,"陆小二","男","专业A","未分班","北京","统计学","招生计划A","13581851095");
        StudentListProperty studentListProperty05 = new StudentListProperty(5,2034,"陆小三","男","专业A","未分班","北京","政治学  ","招生计划A","13581801795");
        StudentListProperty studentListProperty06 = new StudentListProperty(6,2035,"陆小四","男","专业A","未分班","北京","经济学基础","招生计划A","13581804095");
        StudentListProperty studentListProperty07 = new StudentListProperty(7,2036,"陆小五","男","专业A","未分班","北京","新闻学","招生计划A","13541801095");
        //放入集合
        ArrayList<StudentListProperty> studentListProperties = new ArrayList<>();
        studentListProperties.add(studentListProperty01);
        studentListProperties.add(studentListProperty02);
        studentListProperties.add(studentListProperty03);
        studentListProperties.add(studentListProperty04);
        studentListProperties.add(studentListProperty05);
        studentListProperties.add(studentListProperty06);
        studentListProperties.add(studentListProperty07);
        //将用户数据集合转换成Javafx组件集合
        ObservableList<StudentListProperty> studentListProperties1 = FXCollections.observableArrayList(studentListProperties);
        //把数据放入表格当中
        table.setItems(studentListProperties1);
        //配置列映射，让每一列知道要展示的属性是哪一个
        iDXClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,Integer>("iDX"));
        stuNOClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,Integer>("stuNO"));
        nameClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("name"));
        genderClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("gender"));
        majorClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("major"));
        classRoomClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("classRoom"));
        studyCenterClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("studyCenter"));
        trainingClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("training"));
        epnPlanClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,Integer>("epnPlan"));
        mobileNOClu.setCellValueFactory(new PropertyValueFactory<ViewResultProperty,String>("mobileNO"));

        //分页查询
        HBox hBox1 = new HBox();
        hBox1.setSpacing(6);
        hBox1.setAlignment(Pos.CENTER_RIGHT);
        Label firstLab  = new Label("<<首页");
        //颜色
        Color rgb3 = Color.rgb(120,185,0);
        firstLab.setTextFill(rgb3);
        Label lastLab = new Label("<<上一页");
        lastLab.setTextFill(rgb3);
        Button oneLab = new Button("1");
        Button twoLab = new Button("2");
        Button threeLab = new Button("3");
        Button fourLab = new Button("4");
        Label nextLab = new Label("下一页>>");
        nextLab.setTextFill(rgb3);
        Label endLab = new Label("尾页>>");
        endLab.setTextFill(rgb3);
        Label allLab = new Label("总记录数100条");
        TextField pageTF = new TextField();
        pageTF.setPrefWidth(20);
        Label pageLab = new Label("/10");
        Button goBtn = new Button("GO");
        hBox1.getChildren().addAll(firstLab,lastLab,oneLab,twoLab,threeLab,fourLab,nextLab,endLab,allLab,pageTF,pageLab,goBtn);

        //返回按钮
        HBox hBox2 = new HBox();
        hBox2.setAlignment(Pos.CENTER);
        Button backBtn = new Button("返回");
        backBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        //事件
        BackBtnAction backBtnAction = new BackBtnAction();
        backBtn.setOnAction(backBtnAction);

        backBtn.setPrefWidth(100);
        hBox2.getChildren().add(backBtn);
        //界面添加组件
        this.getChildren().addAll(topLab,hBox,table,hBox1,hBox2);
    }
}
